#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        vector<vector<int>> dp(text1.size() + 1, vector<int>(text2.size() + 1, 0));
        for (int i = 1; i < text1.size() + 1; i++)
        {
            for (int j = 1; j < text2.size() + 1; j++)
            {
                if (text1[i - 1] == text2[j - 1])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
        return dp[text1.size()][text2.size()];
    }
};

class Solution {
public:
    int maxUncrossedLines(vector<int>& nums1, vector<int>& nums2) {
        vector<vector<int>> dp(nums1.size() + 1, vector<int>(nums2.size() + 1, 0));
        for (int i = 1; i < nums1.size() + 1; i++)
        {
            for (int j = 1; j < nums2.size() + 1; j++)
            {
                if (nums1[i - 1] == nums2[j - 1])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
        return dp[nums1.size()][nums2.size()];
    }
};

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        vector<vector<int>>dp(nums.size(), vector<int>(nums.size(), 0));
        dp[0][0] = nums[0];
        for (int i = 1; i < nums.size(); i++)
        {
            dp[0][i] = dp[0][i - 1] + nums[i];
        }
        int ret = nums[0];
        for (int i = 0; i < nums.size(); i++)
        {
            dp[i][i] = nums[i];
            ret = max(ret, dp[i][i]);
            for (int j = i + 1; j < nums.size(); j++)
            {
                dp[i][j] = dp[i][j - 1] + nums[j];
                ret = max(ret, dp[i][j]);
            }
        }
        return ret;
    }
};

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        vector<int>dp(nums.size(), 0);
        dp[0] = nums[0];
        int ret = dp[0];
        for (int i = 1; i < nums.size(); i++)
        {
            dp[i] = max(dp[i - 1] + nums[i], nums[i]);
            ret = max(ret, dp[i]);
        }
        return ret;
    }
};